/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "mud_item" )
@IdClass( MudItemPK.class)
@NamedQueries( { @NamedQuery( name = "MudItem.findByItemId", query =
                                                             "SELECT m FROM MudItem m WHERE m.itemId = :itemId" ),
                 @NamedQuery( name = "MudItem.findByItemClassId", query =
                                                                  "SELECT m FROM MudItem m WHERE m.itemClassId = :itemClassId" ) } )
public class MudItem implements Serializable {
  private static final long serialVersionUID = 1L;  
  @Id
  @Column( name = "item_class_id", nullable = false )
  private int itemClassId;

  @Id
  @GeneratedValue( strategy=GenerationType.SEQUENCE )  
  @Column( name = "item_id", nullable = false )
  private int itemId;
  
  @OneToMany( cascade = CascadeType.ALL, mappedBy = "mudItem" )
  private Collection<UserCharItem> userCharItemCollection;
  @OneToMany( cascade = CascadeType.ALL, mappedBy = "mudItem" )
  private Collection<MudItemAttr> mudItemAttrCollection;
  @JoinColumn( name = "item_class_id", referencedColumnName = "item_class_id", insertable =
                                                                               false, updatable =
                                                                                      false )
  @ManyToOne
  private MudItemClass mudItemClass;


  public MudItem() {
  }


  public MudItem( int itemId, int itemClassId ) {
     this.itemId = itemId;
    this.itemClassId = itemClassId;
  }


   public int getItemId() {
    return itemId;
  }


  public void setItemId( int itemId ) {
    this.itemId = itemId;
  }


  public int getItemClassId() {
    return itemClassId;
  }


  public void setItemClassId( int itemClassId ) {
    this.itemClassId = itemClassId;
  }
  
  public Collection<UserCharItem> getUserCharItemCollection() {
    return userCharItemCollection;
  }


  public void setUserCharItemCollection( Collection<UserCharItem> userCharItemCollection ) {
    this.userCharItemCollection = userCharItemCollection;
  }


  public Collection<MudItemAttr> getMudItemAttrCollection() {
    return mudItemAttrCollection;
  }


  public void setMudItemAttrCollection( Collection<MudItemAttr> mudItemAttrCollection ) {
    this.mudItemAttrCollection = mudItemAttrCollection;
  }


  public MudItemClass getMudItemClass() {
    return mudItemClass;
  }


  public void setMudItemClass( MudItemClass mudItemClass ) {
    this.mudItemClass = mudItemClass;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) itemId;
    hash += (int) itemClassId;
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof MudItem ) ) {
      return false;
    }
    MudItem other = (MudItem) object;
    if ( this.itemId != other.itemId ) {
      return false;
    }
    if ( this.itemClassId != other.itemClassId ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.MudItem[itemId=" + itemId + ", itemClassId=" + itemClassId + "]";
  }

}
